#include "videoTexture.h"

//=================================================================================
void videoTexture::draw(ofPoint2f pts[4]){

	glEnable(GL_TEXTURE_2D);
	
	// bind the texture
	glBindTexture( GL_TEXTURE_2D, (GLuint)getTextureName() );
			
		// -------------------------------------------------
		// complete hack to remove border artifacts.
		// slightly, slightly alters an image, scaling...
		// to remove the border.
		// we need a better solution for this, but
		// to constantly add a 2 pixel border on all uploaded images
		// is insane.. 
		float offsetw = 0; ///1.0f/(getTextureWidth()*2.0f);
		float offseth = 0;//1.0f/(getTextureHeight()*2.0f);
		// -------------------------------------------------
		
		float tx0 = 0+offsetw;
		float ty0 = 0+offseth;
		float tx1 = getTextureCoordT() - offsetw;
		float ty1 = getTextureCoordU() - offseth;
		
		if (getFlipped() == true){
			glBegin( GL_QUADS );
				glTexCoord2f(tx0,ty1);			glVertex3f(pts[0].x, pts[0].y,0);
				glTexCoord2f(tx1,ty1);			glVertex3f(pts[1].x, pts[1].y,0);
				glTexCoord2f(tx1,ty0);			glVertex3f(pts[2].x, pts[2].y,0);
				glTexCoord2f(tx0,ty0);			glVertex3f(pts[3].x, pts[3].y,0);
			glEnd();
		} else {
			glBegin( GL_QUADS );
				glTexCoord2f(tx0,ty0);			glVertex3f(pts[0].x, pts[0].y,0);
				glTexCoord2f(tx1,ty0);			glVertex3f(pts[1].x, pts[1].y,0);
				glTexCoord2f(tx1,ty1);			glVertex3f(pts[2].x, pts[2].y,0);
				glTexCoord2f(tx0,ty1);			glVertex3f(pts[3].x, pts[3].y,0);
			glEnd();
		}
	glDisable(GL_TEXTURE_2D);
	
}
